package com.song.service.Impl;

import com.song.dao.MenuMapper;
import com.song.pojo.Menu;
import com.song.service.MenuService;
import com.song.vo.MenuVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 宋超
 * HP - the login name of the current user.
 * 2020/12/6 - the current system date.
 * 9:45 - the current system time.
 */
@Service
@Transactional
public class MenuServiceImpl implements MenuService {
    @Resource
    private MenuMapper menuMapper;

    //查询所有菜单
    public List<Menu> findMenuList() {
        List<Menu> menuList = menuMapper.findMenuList();
        return menuList;
    }

    //根据角色ID查询该角色拥有的菜单ID集合
    public List<Integer> findMenuIdListByRoleId(int roleId) {
        return menuMapper.findMenuIdListByRoleId(roleId);
    }

    //根据菜单编号查询菜单信息
    public List<Menu> findMenuByMenuId(List<Integer> currentRoleMenuIds) {
        return menuMapper.findMenuByMenuId(currentRoleMenuIds);
    }

    //查询菜单列表
    public List<Menu> findMenuListByPage(MenuVo menuVo) {
        return menuMapper.findMenuListByPage(menuVo);
    }


    //添加菜单
    public int addMenu(Menu menu) {
        if(menu.getId()==null){
            menu.setId(0);
        }
        menu.setTarget("_self");
        return menuMapper.addMenu(menu);
    }

    //修改菜单
    public int updateMenu(Menu menu) {
        return menuMapper.updateMenu(menu);
    }

    //查询此菜单下是否有子菜单
    public int getMenuCountByMenuId(Integer id) {
        return menuMapper.getMenuCountByMenuId(id);
    }


    //删除菜单
    public int deleteById(Integer id) {
        return menuMapper.deleteById(id);
    }


    //根据当前登录员工的角色查询菜单列表
    public List<Menu> findListByEmployeeId(Integer employeeId) {
        return menuMapper.findListByEmployeeId(employeeId);
    }
}
